home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 1
/
Nebula One.iso
/
Utilities
/
Converters
/
Convert_MacPaint
/
Source
/
PSstuff
/
PackedCode
< prev
next >
Wrap
Text File
|
1995-06-12
|
3KB
|
115 lines
%BEGIN MacPaint
%
% Define values for: the 'length' byte and a byte when a run is found
% define a string to be used when reading a byte that has been repeated
/lengthByte 1 string def
/runByte 1 string def
%
% - unpackbytes -
%
% This unpacks packed hex data into binary strings. Data format is
% identical to PS level 2 RLE and the same as Mac PackBits (plus
% terminating 80). Data is divided into chunks. Each chunk starts with
% a 'length' byte. if byte is < 128 use that number of following bytes
% (plus one) literally. if byte is > 128, next byte should be used
% 257-(thatbyte) times 128 (80) is improperly dealt with here if it
% appears in the data (it is an error when it does) Ignoring 128 saves
% time, tho, and all files using this are well formed and don't use it.
%
/unpackbytes
{
% get the length byte
/thelength
currentfile lengthByte readhexstring pop
0 get
def
thelength 128 lt
{
% the length byte says copy thelength bytes literally
/dataString thelength 1 add string def
currentfile dataString readhexstring pop
}
{
% the length byte says copy next byte 257-thelength times
/runlength 257 thelength sub def
/runString runlength string def
currentfile runByte readhexstring pop pop
0 1 runlength 1 sub
{ runString exch runByte putinterval }
for
runString
}
ifelse
} def
%
% - level1showimage -
%
% This reads the packed data in, unpacks it, and displays the image
% properly. It also reads and discards the terminating byte (80).
% and > character which is eof for the asciihexdecode filter.
%
/level1showimage
{
576 720 scale
576 720 1
[576 0 0 -720 0 720]
{unpackbytes}
image
% Discard the final 80 byte.
currentfile lengthByte readhexstring pop pop
currentfile read pop pop
} def
%
% - level2showimage -
%
% This reads the image data in, and displays the image properly,
% letting a runlength filter decode the packed data. Since this is
% PS level 2, we don't need the data source to be a procedure.
%
/level2showimage
{
576 720 scale
576 720 1
[576 0 0 -720 0 720]
currentfile /ASCIIHexDecode filter /RunLengthDecode filter
image
} def
%
% PSlevel
%
% This stores a number describing the PS level of the current
% environment. If possible, it uses the level2 langlevel,
% otherwise it assumes 1
%
/PSlevel
systemdict /languagelevel known
{languagelevel}
{1}
ifelse
def
/showMPimage
{
PSlevel 2 lt
{ level1showimage }
{ level2showimage }
ifelse
}
def
%END MacPaint